import data.structure.TreeNode;

public class test27 {
    /*给你一个二叉树的根节点 root ， 检查它是否轴对称。



示例 1：

输入：root = [1,2,2,3,4,4,3]
输出：true
*/
    public static void main(String[] args) {
         TreeNode root = new TreeNode(1);
         root.left = new TreeNode(2);
         root.right = new TreeNode(2);
         root.left.left = new TreeNode(3);
         root.left.right = new TreeNode(4);
         root.right.left = new TreeNode(4);
         root.right.right = new TreeNode(3);
         boolean result = isSymmetric(root);
         System.out.println(result);
    }

    public static boolean isSymmetric(TreeNode root) {
         return checkSymmetric(root.left, root.right);
    }

    public static boolean checkSymmetric(TreeNode left, TreeNode right) {
        if (left == null && right == null)
            return true;
        if (left == null || right == null)
            return false;
        return left.val == right.val && checkSymmetric(left.left, right.right) && checkSymmetric(left.right, right.left);
    }
}
